Skip to content

fix: refactor widget addition sagas and widget operation sagas to allow gridPosition in pasteSaga#32992

Merged
rahulbarwal merged 10 commits intoreleasefrom
fix/multiple-drag-drop-bb-canvas-resize-issue
Apr 29, 2024
Merged

fix: refactor widget addition sagas and widget operation sagas to allow gridPosition in pasteSaga#32992
rahulbarwal merged 10 commits intoreleasefrom
fix/multiple-drag-drop-bb-canvas-resize-issue

Conversation

@rahulbarwal
Copy link
Contributor

@rahulbarwal rahulbarwal commented Apr 26, 2024

Description

Tip

Problem
The current building block on canvas implementation uses the pasteSaga logic, and this logic requires the mousePosition to know where to paste the widgets. Due to building blocks being mimicked as a single widget, we get grid position values instead of mouse location when dragging and dropping building blocks, this forced us to create e utility function that generates mousePosition from gridPosition values. This logic was flawed and led to building blocks placement being wrong when the view is scrolled.
Solution
We have decided to implement the pasteSaga to allow both mousePosition and gridPosition as expected values for dropping the copied widgets unto the canvas.

Fixes #32962

Automation

/ok-to-test tags="@tag.Widget"

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/8875384318
Commit: 6f425a3
Cypress dashboard url: Click here!

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Enhanced building block functionalities including new actions and templates for a smoother drag-and-drop experience.
    • Added ability to specify exact grid positions when placing widgets, enhancing layout precision.
  • Refactor

    • Streamlined sagas related to widget operations and building blocks for improved performance and maintainability.
  • Bug Fixes

    • Adjusted widget addition logic to prevent UI issues during drag-and-drop actions.
  • Chores

    • Removed outdated functions and reorganized imports to align with updated functionalities.

@github-actions github-actions bot added Bug Something isn't working Building blocks Building blocks on cavas, on templates listing or drag and drop of building blocks. Low An issue that is neither critical nor breaks a user flow Templates Product Issues related to Templates labels Apr 26, 2024
@rahulbarwal rahulbarwal removed Bug Something isn't working Low An issue that is neither critical nor breaks a user flow labels Apr 26, 2024
@github-actions github-actions bot added Bug Something isn't working Low An issue that is neither critical nor breaks a user flow labels Apr 26, 2024
@rahulbarwal
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

@github-actions
Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/8847157677.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 32992.
recreate: .

@github-actions
Copy link

Deploy-Preview-URL: https://ce-32992.dp.appsmith.com

@github-actions github-actions bot removed the Bug Something isn't working label Apr 26, 2024
@github-actions github-actions bot added the Bug Something isn't working label Apr 26, 2024
@jacquesikot jacquesikot marked this pull request as ready for review April 29, 2024 03:55
@jacquesikot jacquesikot requested review from a team and marks0351 and removed request for a team April 29, 2024 03:55
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 29, 2024

Walkthrough

The changes primarily focus on enhancing the functionality and control flow associated with building blocks in the application, including new additions, modifications, and removals of functions and imports. These updates aim to streamline the process of adding and manipulating building blocks on the canvas, improving user experience and system performance.

Changes

File Path Summary of Changes
.../src/sagas/BuildingBlocksSagas.ts Various modifications related to functions and imports concerning building blocks.
.../src/sagas/CanvasSagas/DraggingCanvasSagas.ts Reorganized imports for building block functions.
.../src/sagas/WidgetAdditionSagas.ts Significant restructuring in building block addition sagas, including removal and renaming of functions.
.../src/sagas/WidgetOperationSagas.tsx Addition of gridPosition parameter for precise widget placement.
.../src/sagas/WidgetOperationUtils.ts Removal of a function calculating mouse positions from canvas grid positions.

Assessment against linked issues

Objective Addressed Explanation
Enhance user experience by enabling drag-and-drop functionality for building blocks on the canvas (#31314)
Implement a skeleton loader widget to indicate a loading state after a building block is dropped (#31314) No direct evidence of a skeleton loader implementation in the provided data.
Streamline the process of integrating building blocks into the user's application (#31314)
Prevent reshuffling of existing widgets when dragging a building block (#32962) Changes in drag and drop functionality suggest potential fixes but unclear.

Possibly related issues


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@jacquesikot jacquesikot changed the title Refactor widget addition sagas and widget operation sagas fix: refactor widget addition sagas and widget operation sagas to allow gridPosition in pasteSaga Apr 29, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Out of diff range and nitpick comments (4)
app/client/src/sagas/BuildingBlocksSagas.ts (1)

10-10: Consider grouping related imports from the same module to improve readability.

app/client/src/sagas/WidgetOperationUtils.ts (3)

Line range hint 1000-1020: Add error handling for potential null values in DOM operations.

+ if (!stickyCanvasDOM) return;

This addition ensures that the function does not attempt to access properties of null, preventing runtime errors.


Line range hint 1022-1045: Define magic numbers as constants for better readability and maintainability.

+ const DEFAULT_PADDING_MULTIPLIER = 2;
  let padding =
    ((LayoutWidget?.layoutSystemType === LayoutSystemTypes.AUTO
      ? AUTO_LAYOUT_CONTAINER_PADDING
      : CONTAINER_GRID_PADDING) +
      WIDGET_PADDING) *
-    2;
+    DEFAULT_PADDING_MULTIPLIER;

This change improves the readability of the code by replacing the magic number with a descriptive constant.


Line range hint 1047-1070: Add error handling for potential null values in DOM operations.

+ if (!containerDOM || !canvasDOM) return;

This addition ensures that the function does not attempt to access properties of null, preventing runtime errors.

Copy link
Contributor Author

@rahulbarwal rahulbarwal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jacquesikot My review revolves around nomenclature. I feel all sagas in the new file have similar name and will confuse us in future.

@mohanarpit
Copy link
Member

@rahulbarwal @jacquesikot Do you think we can write a Jest unit test to assert that this problem won't show up again?

@rahulbarwal
Copy link
Contributor Author

Hey @mohanarpit We have a separate PR for automation in works, We will ensure this case is added there as well.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Out of diff range and nitpick comments (1)
app/client/src/sagas/WidgetAdditionSagas.ts (1)

Line range hint 54-183: The getChildWidgetProps function handles widget properties generation correctly. Consider adding more detailed comments in complex logic sections to improve maintainability.

@jacquesikot jacquesikot added the ok-to-test Required label for CI label Apr 29, 2024
@rahulbarwal
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

@github-actions
Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/8874414837.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 32992.
recreate: .

@github-actions
Copy link

Deploy-Preview-URL: https://ce-32992.dp.appsmith.com

@jacquesikot jacquesikot added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Apr 29, 2024
@mohanarpit
Copy link
Member

Hey @mohanarpit We have a separate PR for automation in works, We will ensure this case is added there as well.

Can you please link to that PR? Also any reason we are writing tests in a separate PR from the actual code? This way of working sounds like a violation of our coding best practices.

@rahulbarwal rahulbarwal merged commit 6dfc093 into release Apr 29, 2024
@rahulbarwal rahulbarwal deleted the fix/multiple-drag-drop-bb-canvas-resize-issue branch April 29, 2024 10:13
@jacquesikot
Copy link
Contributor

@mohanarpit PR for cypress tests for this feature #33036

@mohanarpit
Copy link
Member

@mohanarpit PR for cypress tests for this feature #33036

@jacquesikot Thanks. But my question still stands. Why is the PR for Cypress test separate from the change itself? Why are we not writing the code changes and Cypress tests in the same PR? This way, there is a changelog for our future selves about the code change & the test case to ensure that the code change doesn't regress.

@Nikhil-Nandagopal Nikhil-Nandagopal added Accelerators Product Issues related to app building accelerators and removed Templates Product Issues related to Templates labels Aug 6, 2024
@github-actions github-actions bot added QA Needs QA attention QA Pod Issues under the QA Pod Widgets & Accelerators Pod Issues related to widgets & Accelerators labels Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Accelerators Product Issues related to app building accelerators Bug Something isn't working Building blocks Building blocks on cavas, on templates listing or drag and drop of building blocks. Low An issue that is neither critical nor breaks a user flow ok-to-test Required label for CI QA Pod Issues under the QA Pod QA Needs QA attention Widgets & Accelerators Pod Issues related to widgets & Accelerators

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Existing widgets are reshuffled when dragging a building block

4 participants